package xyz.xtt.exchange.service;

import java.util.Objects;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.asset.client.AssetClient;
import xyz.xtt.asset.client.request.MintRequest;
import xyz.xtt.asset.client.response.MintResponse;
import xyz.xtt.common.response.ApiResult;

@Slf4j
@Service
public class AssetClientService {
	@Autowired
	private AssetClient assetClient;

	public MintResponse mint(String uid, MintRequest mintRequest) {
		ApiResult<MintResponse> assetMintResponse = assetClient.create(uid, mintRequest);
		log.info("assetMintResponse:{}", JSONUtil.toJsonStr(assetMintResponse));
		MintResponse response = Optional.ofNullable(assetMintResponse).filter(ApiResult::isOk).map(ApiResult::getData).orElse(null);
		if (Objects.nonNull(response)) {
			return response;
		}
		return null;
	}
}
